package com.hitnet.hitnet;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

/**
 * Created by juwenz on 15/5/4.
 * 启动后的抉择视图，如果有登录信息，进入主界面，否则进入登录界面
 */
public class SwitchActivity extends Activity{

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);

        //保存token信息到本地
        Context ctx = SwitchActivity.this;
        SharedPreferences sp = ctx.getSharedPreferences("SP", MODE_PRIVATE);
        //存入数据
        SharedPreferences.Editor editor = sp.edit();
        String username = sp.getString("username","");
        String token = sp.getString("token","");

        //判断Token 和username 信息是否有效
        if (!username.isEmpty()
                &&!token.isEmpty()){
            Intent i = new Intent(SwitchActivity.this,MainActivity.class);
            startActivity(i);
        }else{
            Intent i = new Intent(SwitchActivity.this,FaceBookLogin.class);
            startActivity(i);

        }
        SwitchActivity.this.finish();
    }
}
